package ArrayList.PokerCard;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class PlayCard {
    public static final String[] Suits = {"♠","♥","♣","♦"};
    public static List<Card> buyCard() {
        List<Card> list= new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            for (int j = 1; j <= 13; j++) {
                int rank = j;
                Card card = new Card(rank,Suits[i]);
                list.add(card);
            }
        }
        return list;
    }
    public static void shuffle(List<Card> list) {
        Random random = new Random();
        for (int i = list.size()-1; i >0 ; i--) {
            int index = random.nextInt(i);
            swap(list,i,index);
        }
    }
    public static void swap (List<Card> list,int i,int j ){
        Card temp = list.get(i);
        list.set(i,list.get(j));
        list.set(j,temp);
    }

    public static void main(String[] args) {
        List<Card> list = buyCard();
        System.out.println(list);
        shuffle(list);
        System.out.println(list);
        List<List<Card>> hand = new ArrayList<>();//类似二维数组
        List<Card> hand1 = new ArrayList<>();
        List<Card> hand2 = new ArrayList<>();
        List<Card> hand3 = new ArrayList<>();
        hand.add(hand1);
        hand.add(hand2);
        hand.add(hand3);
        //每人抓五张，每次轮流抓一张
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                Card card = list.remove(0);
                hand.get(j).add(card);
            }
        }
        for (int i = 0; i < 3; i++) {
            System.out.println(hand.get(i));
        }
    }
}

